import org.openqa.selenium.By;

import java.io.IOException;

/**
 * @projectName: The-examination-questionnaire-pass-test
 * @package: PACKAGE_NAME
 * @className: QuestionPage
 * @author: Tongxinxin
 * @description: 题库界面功能测试
 * @date: 2025/9/22 0:32
 * @version: 1.0
 */
public class QuestionPage extends Util{
    public QuestionPage(String url) {
        super(url);
    }
    public static String url="http://8.155.1.153:8081/repo/index";
    //未登录状态下进入模板广场页面
    public void NoLoginQe() throws IOException {
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.top___1C1Zi > div.header___5xZ3f > span"));

        //判断是否返回登录页面
        String expect=driver.getTitle();

        getScreenShot(getClass().getName());
        assert expect.equals("问卷考试系统");
    }

    //登录状态下访问我的题库页面
    public void LoginQe() throws InterruptedException, IOException {
        //进行登录进入首页
        driver.findElement(By.cssSelector("#username")).sendKeys("tong");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button > span")).click();

        //点击题库中心
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(4) > div > span > div")).click();
        Thread.sleep(3000);
        //点击我的题库
        //driver.findElement(By.cssSelector("#rc-menu-uuid-94365-11-\\/repo-popup > li.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child.ant-pro-base-menu-menu-item > span > div > span")).click();
        driver.findElement(By.xpath("//li[@title=\"我的题库\"]")).click();

        //点击“新建”按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-pro-table-list-toolbar > div > div.ant-space.ant-space-horizontal.ant-space-align-center.ant-pro-table-list-toolbar-right > div:nth-child(1) > div > div:nth-child(1) > button > span:nth-child(2)")).click();

        //输入题库名称
        Thread.sleep(2000);
        //driver.findElement(By.cssSelector("#name")).sendKeys("测试");
        driver.findElement(By.xpath("//input[@placeholder=\"请输入题库名称\"]")).sendKeys("测试");
        Thread.sleep(2000);
        //选择题库类型
        driver.findElements(By.cssSelector("#mode")).get(1).click();
        Thread.sleep(1000);
        // 点击问卷
        driver.findElements(By.xpath("//span[text() = \"问卷\"]")).get(3).click();
        //点击”确定“按钮
        driver.findElement(By.cssSelector("body > div:nth-child(9) > div > div.ant-drawer-content-wrapper > div > div > div.ant-drawer-footer > div > div > div:nth-child(2) > button > span")).click();

        //检查是否创建成功
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-pro-table-list-toolbar > div > div.ant-pro-table-list-toolbar-left > div"));
        String el=driver.getTitle();

        getScreenShot(getClass().getName());
        assert el.equals("题库列表");

    }

    //重置功能
    public void LoginReset() throws InterruptedException, IOException, IOException {
        //进行登录进入首页
        driver.findElement(By.cssSelector("#username")).sendKeys("tong");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.main___x4OjT > div > form > button > span")).click();

        //点击题库中心
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(4) > div > span > div")).click();
        Thread.sleep(3000);
        //点击我的题库
        //driver.findElement(By.cssSelector("#rc-menu-uuid-94365-11-\\/repo-popup > li.ant-menu-item.ant-menu-item-selected.ant-menu-item-only-child.ant-pro-base-menu-menu-item > span > div > span")).click();
        driver.findElement(By.xpath("//li[@title=\"我的题库\"]")).click();
        //点击重置按钮
        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(3) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(1) > button > span")).click();

        driver.findElement(By.cssSelector("#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div:nth-child(2) > div > div.ant-table-wrapper > div > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(8) > span"));
        String el=driver.getTitle();

        getScreenShot(getClass().getName());
        assert el.equals("13");
    }
}
